const KEY = 'vue_xy_info'
const USERINFO_KEY = 'vue_xy_userInfo_info'
export function setToken(token) {
    window.localStorage.setItem(KEY, token);
}


export function getToken() {
    return window.localStorage.getItem(KEY);
}


export function removeToken() {
    window.localStorage.removeItem(KEY);
}

export function saveUserInfo(userInfo) {
    //ls只能存储字符串
    var userInfoStr = JSON.stringify(userInfo);
    window.localStorage.setItem(USERINFO_KEY, userInfoStr)

}

export function getUserInfo() {
    var userInfoStr = window.localStorage.getItem(USERINFO_KEY)
    if (userInfoStr !== '' && userInfoStr !== 'undefined') {
        // 从ls取出userInfo对象并返回
        return JSON.parse(userInfoStr)
    } else {
        return {}
    }
}


export function removeUserInfo() {
    window.localStorage.removeItem(USERINFO_KEY)
}

// 清除所有的登录信息
export function clearLogin() {
    removeToken()
    removeUserInfo()
}